#pragma once

#include "RBTree.hpp"


namespace yfy
{
    template <class K, class V>
    class map 
    {
        struct MapKeyOfT
        {
            const K& operator()(const pair<const K, V>& kv)
            {
                return kv.first;
            }
        };
    private:
        RBTree<K, pair<const K, V>, MapKeyOfT> _t;
    public:
    typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::iterator iterator;        
        typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::const_iterator const_iterator;

        iterator begin()
        {
            return _t.begin();
        }
        iterator end()
        {
            return _t.end();
        }
        
        pair<iterator, bool> Insert(const pair<const K, V>& kv)
        {
            return _t.Insert(kv);
        }

        V& operator[](const K& key)
        {
            pair<iterator, bool> ret = _t.Insert(make_pair(key, V()));
            return ret.first->second;
        }
    };
}
